/*
 * pnlRPS.java
 *
 * Created on Nov 9, 2011, 1:39:45 AM
 */
package GUI;

import java.awt.Dimension;
import java.util.Random;

/**
 *
 * @author Pavel - Old Macbook Pro
 */
public class pnlRPS extends javax.swing.JPanel{

    /** Creates new form pnlRPS */
    public pnlRPS() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {
    	
    	win = 0;
    	loss = 0;

        jSeparator1 = new javax.swing.JSeparator();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton(); 
        jButton2 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jSeparator2 = new javax.swing.JSeparator();
        jSeparator3 = new javax.swing.JSeparator();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        
        setPreferredSize(new Dimension(500, 500));

        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
        add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(32, 101, -1, -1));

        jLabel1.setText("Player Input:");
        add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 20, -1, -1));

        jLabel2.setText("Computer:");
        add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 131, -1, -1));
        add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 91, -1, -1));

        jButton1.setText("Recognize Player Input");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jButton1MouseReleased(evt);
            }
        });
        add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(32, 45, -1, -1));

        //jTextField1.setText("Rock");
        add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(184, 45, 111, -1));

        jLabel4.setText("Randomly Generated:");
        add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 167, -1, -1));

        //jTextField2.setText("Scissors");
        add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(187, 161, 109, -1));
        add(jSeparator2, new org.netbeans.lib.awtextra.AbsoluteConstraints(44, 101, 251, -1));
        add(jSeparator3, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 203, 256, 10));

        //jLabel5.setText("You Win!");
        add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 225, -1, -1));
        
        jButton2.setText("Reset Scores");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jButton2MouseReleased(evt);
            }
        });
        add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(32, 275, -1, -1));
        
        jLabel6.setText("Wins: " + win + "   Losses: " + loss);
        add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(184, 280, -1, -1));
    }// </editor-fold>                        

    
    private void jButton1MouseReleased(java.awt.event.MouseEvent evt) {                                       
    	
    	String computer;
        
    	// TODO Get the gesture here and get its name
    	String gestureName = "Rock"; 
    	
    	//It must be a valid gesture for the game if not we tell them its invalid and ask them to try again
    	if(gestureName.equals("Rock") || gestureName.equals("Paper") || gestureName.equals("Scissors")){
    	
	    	Random rand = new Random();
	    	int temp = rand.nextInt(3);
	    		
	    	if(temp == 0)
	    		computer = "Rock";
	    	else if(temp == 1)
	    		computer = "Paper";
	    	else if(temp == 2)
	    		computer = "Scissors";
	    	else
	    		computer = "Problem with random";	//I tested and this will never happen but better to have something than nothing
	    	
	    	jTextField1.setText(gestureName);
	    	jTextField2.setText(computer);
	    	
	    	if(computer.equals(gestureName)){
	    			jLabel5.setText("Tie");
	    	}
	    	else if(gestureName.equals("Rock")){
	    		if(computer.equals("Paper")){
	    			jLabel5.setText("You Lose");
	    			loss++;
	    		}
	    		else if(computer.equals("Scissors")){
	    			jLabel5.setText("You Win!");
	    			win++;
	    		}
	    	}
	    	else if(gestureName.equals("Paper")){
	    		if(computer.equals("Rock")){
	    			jLabel5.setText("You Win!");
	    			win++;
	    		}
	    		else if(computer.equals("Scissors")){
	    			jLabel5.setText("You Lose");
	    			loss++;
	    		}
	    	}
	    	else{
	    		if(computer.equals("Paper")){
	    			jLabel5.setText("You Win!");
	    			win++;
	    		}
	    		else if(computer.equals("Rock")){
	    			jLabel5.setText("You Lose");
	    			loss++;
	    		}
	    	}
	    	
	    	jLabel6.setText("Wins: " + win + "   Losses: " + loss);
    	
    	}
    	else{
    		jTextField1.setText("Invalid Gesture");
	    	jTextField2.setText("Try Again");
    	}

    }
    
    private void jButton2MouseReleased(java.awt.event.MouseEvent evt) {   
    	win = 0; 
    	loss = 0;
    	
    	jLabel6.setText("Wins: " + win + "   Losses: " + loss);
    }
    
    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private int win, loss;

}
